package tv.acgn.advertisement.zuul.filter;

import java.time.LocalDateTime;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import org.springframework.stereotype.Component;

/**
 * @program: advertisement
 * @description: 网关-前置过滤器-时间日期过滤器
 * @author: junG
 * @create: 2019-04-21 23:29
 **/

@Slf4j
@Component
public class DateTimeStatisticPreRequestFilter extends ZuulFilter {

    @Override
    public String filterType() {
        return FilterConstants.PRE_TYPE;
    }

    @Override
    public int filterOrder() {
        return 0;
    }

    @Override
    public boolean shouldFilter() {
        return true;
    }

    @Override
    public Object run() throws ZuulException {
        RequestContext requestContext = RequestContext.getCurrentContext();
        log.trace("请求进入网关 记录时间");
        requestContext.set("reqStartTime", LocalDateTime.now());
        return null;
    }
}
